package com.example.learn.leetcode;

public class _88合并两个有序数组 {

    public void merge(int[] nums1, int m, int[] nums2, int n) {
        if(m==1) return;
        int resIndex = m-1;
        int subIndex = n-1;
        int resEndIndex =0;
        while(resEndIndex<m-1&&nums1[resEndIndex]!=0){
            resEndIndex++;
        }
        if(resEndIndex==m) resEndIndex = m-1;
        while(resIndex>=0&&resEndIndex>=0&&subIndex>=0){
            if(nums1[resEndIndex]>nums2[subIndex]){
                nums1[resIndex] = nums1[resEndIndex];
                nums1[resEndIndex]=0;
                resEndIndex--;
            }else{
                nums1[resIndex] = nums1[subIndex];
                subIndex--;
            }
            resIndex--;


        }


    }

    public static void main(String[] args) {
        
    }
}
